package com.niit;

/**
 * @Author cheng
 * @Date 2022 10 13 14 46
 **/
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//


import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonUtils {


    static ObjectMapper objectMapper;

    /*
     * 解析json
     */
    public static <T> T fromJson(String content, Class<T> valueType) {
        if (objectMapper == null) {
            objectMapper = new ObjectMapper();
        }
        try {
            return objectMapper.readValue(content, valueType);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /*
     * 生成json
     */
    public static String toJson(Object object) {

        if (objectMapper == null) {
            objectMapper = new ObjectMapper();
        }

        try {
            // 通过 fastJson 只要这样去写 ， 返回json
            return  objectMapper.writeValueAsString( object );

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }



}
